package com.diaohw.module.system.obj.tables;

import com.diaohw.platform.framework.db.flex.obj.tables.BaseTableDef;
import com.mybatisflex.core.query.QueryColumn;

import java.io.Serial;

/**
 * 系统权限 表定义层。
 *
 * @author D-Hw
 * @since 2024-11-15 18:22:15
 */
public class PermissionDef extends BaseTableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 系统权限
     */
    public static final PermissionDef PERMISSION = new PermissionDef();

    /**
     * 对应的页面ID
     */
    public final QueryColumn MENU_ID = new QueryColumn(this, "MENU_ID");

    /**
     * 权限code
     */
    public final QueryColumn PERMISSION_CODE = new QueryColumn(this, "PERMISSION_CODE");

    /**
     * 权限名称
     */
    public final QueryColumn PERMISSION_NAME = new QueryColumn(this, "PERMISSION_NAME");


    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{PERMISSION_NAME, PERMISSION_CODE, MENU_ID};

    public PermissionDef() {
        super("", "PERMISSION");
    }

    private PermissionDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public PermissionDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new PermissionDef("", "PERMISSION", alias));
    }

}
